<?php


namespace App\Http\Controllers\CmsApi;

use App\Http\Controllers\BaseController;
use App\Http\Model\Hint;
use App\Http\Services\SuggestRoomListServices;
use App\Lib\Response;
use Illuminate\Http\Request;

class SuggestRoomListController extends BaseController
{
    protected $service;//首页推荐房间


    public function __construct()
    {
        $this->service = new SuggestRoomListServices();
    }

    //更改推荐房间状态
    public function chageStatus(Request $request){
        $param = $request->all();
        $changeStatus = $this->service->chageStatus($param);
        if ($changeStatus['code'] == Hint::SUCCESS) {
            Response::returnResult(Hint::SUCCESS, $changeStatus);
        } else {
            Response::returnResult(Hint::ERR_DB_FAIL, $changeStatus);
        }
    }

    //添加数据或修改数据
    public function addOrUpdate(Request $request){
        $id = $request->post('id',0);//编辑id
        $room_id = $request->post('room_id',0);//房间id
        $start_time = $request->post('start_time','');//开始时间
        $end_time = $request->post('end_time','');//结束时间
        $sort = $request->post('sort',0);//权重
        $is_show = $request->post('is_show',1);//1=显示 0=不显示
        if(empty($start_time) || empty($end_time) || empty($sort) || empty($room_id) ){
            return Response::returnResult(Hint::PARAM_ERROR);
        }
        $res = $this->service->addOrUpdate($id, $room_id, $start_time, $end_time, $sort, $is_show);
        if ($res['code'] == Hint::SUCCESS) {
            Response::returnResult(Hint::SUCCESS);
        } else {
            Response::returnResult(Hint::ERR_DB_FAIL, $res);
        }
    }
}
